package com.learn.authorization.config;

import com.learn.authorization.pojo.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/04/16
 * @description 自定义的权限处理
 */
@Component("ex")
public class MyExpressionRoot {
    public boolean hasAuthority(String authority) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        Set<String> permissions = loginUser.getPermissions();
        return permissions.contains(authority);
    }
}
